package com.paomi.client.activity.pay.adapter;

import android.app.Activity;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.paomi.client.R;
import com.paomi.client.activity.takeTicket.model.TakeTicketBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PayPurchaserAdapter extends RecyclerView.Adapter<PayPurchaserAdapter.ViewHolder> {
    Activity activity;
    private List<TakeTicketBean> data = new ArrayList<>();
    Typeface iconType;

    public PayPurchaserAdapter(Activity activity, Typeface iconType) {
        this.activity = activity;
        this.iconType = iconType;
    }

    public void setData(List list) {
        data = list;
        notifyDataSetChanged();
    }

    OnDeleteItemClick deleteItemClick;

    public void setOnDeleteItemClick(OnDeleteItemClick onDeleteItemClick) {
        this.deleteItemClick = onDeleteItemClick;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = null;
        view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_person_pay, parent, false);
        ViewHolder viewHolder = new ViewHolder(view, true);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        if (position < data.size()) {
            final TakeTicketBean entity = data.get(position);
            holder.tv_name.setText(entity.getName());
            String cardType = "";
//            if (entity.type == 1) {
//                cardType = "身份证:     ";
//            } else if (entity.type == 2) {
//                cardType = "护照:     ";
//            } else if (entity.type == 3) {
//                cardType = "港澳通行证:     ";
//            } else if (entity.type == 4) {
//                cardType = "台胞证:     ";
//            }
            if(entity.getMobile()!=null){
                holder.tv_id.setText(cardType + entity.getMobile());
            }else{
                holder.tv_id.setText(cardType + entity.getCode());
            }
            holder.iv_delete.setTypeface(iconType);
            holder.iv_delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    entity.setSelect(false);
                    if (deleteItemClick != null) {
                        deleteItemClick.deleteItem(entity);
                    }
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public interface OnDeleteItemClick {
        void deleteItem(TakeTicketBean pos);
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_name)
        TextView tv_name;
        @BindView(R.id.tv_id)
        TextView tv_id;
        @BindView(R.id.iv_delete)
        TextView iv_delete;

        public ViewHolder(View itemView, boolean isItem) {
            super(itemView);
            if (isItem) {
                ButterKnife.bind(this, itemView);
            }
        }
    }
}
